﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Direct.ApplicationModel;
using Direct.Core;

namespace Direct.Mvc
{
    public class AppModelController : ServerControllerBase
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="aid">Application Id</param>
        /// <param name="mid">Menu Id</param>
        /// <returns></returns>
        public ActionResult NavMenu(String aid, String mid)
        {
            var appModelService = ServiceLocator.GetInstance<IApplicationModelService>();
            var app = appModelService.GetApplication(aid);
            if (app == null)
                return Content("Application not found: {0}".Templ(aid));
            var item = app.Commands.FindItem(mid);
            if (item == null)
                return Content("Menu item not found: {0}".Templ(mid));

            var view = app.CreateDefaultNavigationPage();
            return View(view, item);
        }
    }
}
